﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Simple.Tools.Verify
{
    /// <summary>
    /// 验证实体字段是否合法
    /// </summary>
    [AttributeUsage(AttributeTargets.Property)]
    public abstract class BaseVerifyAttribute:Attribute
    {
        /// <summary>
        /// 错误信息
        /// </summary>
        protected virtual string _errorInfo { get; set; }
        /// <summary>
        /// 属性名称
        /// </summary>
        protected virtual string _name { get; set; }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="name">属性名称必须填写</param>
        public BaseVerifyAttribute(string name)
        {
			_name = name;
        }
        /// <summary>
        /// 获取错误信息
        /// </summary>
        /// <returns></returns>
        protected virtual string GetErrorInfo()
        {
            return $"{_name}{_errorInfo}";
        }

        /// <summary>
        /// 返回元祖 item_1-信息 item_2-验证结果
        /// </summary>
        /// <param name="o">对象</param>
        /// <param name="prop">属性</param>
        /// <returns></returns>
        public virtual Tuple<string,bool> Verify(object o, PropertyInfo prop)
        {
            return Tuple.Create(GetErrorInfo(),true);
        }
    }
}
